///*
// * To change this template, choose Tools | Templates
// * and open the template in the editor.
// */
//package mainpackage;
//
//import java.io.IOException;
//import javax.bluetooth.BluetoothStateException;
//import javax.bluetooth.DiscoveryAgent;
//import javax.bluetooth.LocalDevice;
//import javax.bluetooth.RemoteDevice;
//import javax.bluetooth.UUID;
//import javax.microedition.io.Connector;
//import javax.microedition.io.StreamConnection;
//import javax.microedition.io.StreamConnectionNotifier;
//import javax.swing.JOptionPane;
//
///**
// *
// * @author MH
// */
//public class ServiceManager {
//
//    private static final UUID SERVER_UUID = new UUID(0x1101);
//    private static final String SERVER_NAME = "MHRemoteServer";
//    private LocalDevice localDevice;
//    private StreamConnectionNotifier notifier;
//
//    public void start() {
//        try {
//            localDevice = LocalDevice.getLocalDevice();
//            localDevice.setDiscoverable(DiscoveryAgent.GIAC);
//        } catch (BluetoothStateException ex) {
//            JOptionPane.showMessageDialog(null, "Connect the Bluetooth device and start the program again");
//            System.exit(0);
//        }
//        String url = "btspp://" + "localhost:" + SERVER_UUID.toString() + ";name=" + SERVER_NAME + ";authorize=false";
//        echo("Server: " + localDevice.getFriendlyName() + " : " + localDevice.getBluetoothAddress());
//        try {
//            notifier = (StreamConnectionNotifier) Connector.open(url);
//        } catch (IOException ex) {
//            echo("Error: " + ex.getMessage());
//        }
//        echo("waiting");
//        waitAndAccept();
//    }
//
//    private void waitAndAccept() {
//        try {
//            StreamConnection conn = notifier.acceptAndOpen();
//            RemoteDevice remote = RemoteDevice.getRemoteDevice(conn);
//
//            echo("connected to " + remote.getFriendlyName(false) + " : " + remote.getBluetoothAddress());
//            new HandleDevice().start(conn);
//        } catch (IOException ex) {
//            echo("error in waiting: " + ex.getMessage());
//        }
//    }
//
//    public void echo(String text) {
//        System.out.println(text);
//    }
//}